{
 "metadata": {
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  },
  "orig_nbformat": 4,
  "kernelspec": {
   "name": "python3",
   "display_name": "Python 3.7.1 64-bit ('Python3_7_2')"
  },
  "interpreter": {
   "hash": "ceed3ede7d2ae4746b1bde0ed48f83d28ba93d0b68e140a25bb2fbb7cbabeb22"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2,
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import pandas as pd \n",
    "import numpy as np\n",
    "import tensorflow as tf\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "#标签\n",
    "FILE_NAMES = ['cowper.txt', 'derby.txt', 'butler.txt']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "lines_list = []\n",
    "labels_list = []"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "for i in range(len(FILE_NAMES)):\n",
    "    lines = []\n",
    "    with open(FILE_NAMES[i],'r',encoding='utf8') as r:\n",
    "        lines = r.readlines()\n",
    "        lines_list.extend(lines)\n",
    "    labels_list.extend([i]*len(lines))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "49608 49608\n"
     ]
    }
   ],
   "source": [
    "print(len(lines_list),len(labels_list))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "import random"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "angry away--even so did Ajax, sorely against his will, retreat angrily\n 2\nDanaans, for I see that I have no thanks for all my fighting. He that\n 2\nStretch'd tight the reins, and hook'd them fast behind.\n 0\naimed a bronze-tipped arrow at him as he was leaving the field, and hit\n 2\nMolest them more in conflict for the dead.\n 0\n"
     ]
    }
   ],
   "source": [
    "for i in range(5):\n",
    "    num = random.randint(0,len(lines_list))\n",
    "    print(lines_list[num],labels_list[num])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "#将以空格隔开的长语句转成词索引列表\n",
    "from tensorflow.keras.preprocessing.text import Tokenizer\n",
    "from tensorflow.keras.preprocessing.sequence import pad_sequences"
   ]
  },
  {
   "source": [
    "#tensorflow.keras.preprocessing.text.Tokenizer是一个非常好用的分词器，支持对空格隔开的中文长语句进行操作,千万不用用函数，否则就验证数据时就不好转换了\n",
    "# def convert(test_list):\n",
    "#     t = Tokenizer()\n",
    "#     t.fit_on_texts(test_list)\n",
    "#     result = t.texts_to_sequences(test_list)\n",
    "#     return result  #返回的是一个大列表，里面每个元素是也是一共列表，是长语句分词后的索引列表。一步到位"
   ],
   "cell_type": "code",
   "metadata": {},
   "execution_count": null,
   "outputs": []
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "t = Tokenizer()\n",
    "t.fit_on_texts(lines_list)  #通过fit_on_texts\n",
    "index_lines_list = t.texts_to_sequences(lines_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "<class 'list'>\n"
     ]
    }
   ],
   "source": [
    "print(type(index_lines_list))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "<class 'list'> [10413, 5198, 381, 257, 429, 21]\n"
     ]
    }
   ],
   "source": [
    "print(type(index_lines_list[0]),index_lines_list[0])\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "最长的一句话长度为: 19 最大词索引为: 15536\n"
     ]
    }
   ],
   "source": [
    "#查看最大词数以及最长语句长度\n",
    "max_len_list = []\n",
    "max_index_list = []\n",
    "\n",
    "for i in index_lines_list:\n",
    "    max_index = max(i)\n",
    "    len_sentenc = len(i)\n",
    "    max_index_list.append(max_index)\n",
    "    max_len_list.append(len_sentenc)\n",
    "\n",
    "print(\"最长的一句话长度为:\",max(max_len_list),\"最大词索引为:\",max(max_index_list))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "[110, 90, 114, 302, 1437, 4839, 10053, 12394, 7141, 1712, 993, 2296, 3250, 2923, 1440, 430, 70, 13, 1]\n"
     ]
    }
   ],
   "source": [
    "#统计词长度分布，如果量大，则优化长度\n",
    "len_count_list = []\n",
    "for i in range(1,20):\n",
    "    len_count = max_len_list.count(i)\n",
    "    len_count_list.append(len_count)\n",
    "\n",
    "print(len_count_list)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "import matplotlib.pyplot as plt\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "output_type": "display_data",
     "data": {
      "text/plain": "<Figure size 432x288 with 1 Axes>",
      "image/svg+xml": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\r\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\r\n  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\r\n<!-- Created with matplotlib (https://matplotlib.org/) -->\r\n<svg height=\"248.450937pt\" version=\"1.1\" viewBox=\"0 0 393.840083 248.450937\" width=\"393.840083pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\r\n <defs>\r\n  <style type=\"text/css\">\r\n*{stroke-linecap:butt;stroke-linejoin:round;}\r\n  </style>\r\n </defs>\r\n <g id=\"figure_1\">\r\n  <g id=\"patch_1\">\r\n   <path d=\"M 0 248.450937 \r\nL 393.840083 248.450937 \r\nL 393.840083 0 \r\nL 0 0 \r\nz\r\n\" style=\"fill:none;\"/>\r\n  </g>\r\n  <g id=\"axes_1\">\r\n   <g id=\"patch_2\">\r\n    <path d=\"M 45.989063 224.64 \r\nL 380.789062 224.64 \r\nL 380.789062 7.2 \r\nL 45.989063 7.2 \r\nz\r\n\" style=\"fill:#ffffff;\"/>\r\n   </g>\r\n   <g id=\"patch_3\">\r\n    <path clip-path=\"url(#p7ef7d1cd08)\" d=\"M 61.207244 224.64 \r\nL 74.158888 224.64 \r\nL 74.158888 222.80206 \r\nL 61.207244 222.80206 \r\nz\r\n\" style=\"fill:#1f77b4;\"/>\r\n   </g>\r\n   <g id=\"patch_4\">\r\n    <path clip-path=\"url(#p7ef7d1cd08)\" d=\"M 77.396799 224.64 \r\nL 90.348444 224.64 \r\nL 90.348444 223.136231 \r\nL 77.396799 223.136231 \r\nz\r\n\" style=\"fill:#1f77b4;\"/>\r\n   </g>\r\n   <g id=\"patch_5\">\r\n    <path clip-path=\"url(#p7ef7d1cd08)\" d=\"M 93.586355 224.64 \r\nL 106.537999 224.64 \r\nL 106.537999 222.735226 \r\nL 93.586355 222.735226 \r\nz\r\n\" style=\"fill:#1f77b4;\"/>\r\n   </g>\r\n   <g id=\"patch_6\">\r\n    <path clip-path=\"url(#p7ef7d1cd08)\" d=\"M 109.77591 224.64 \r\nL 122.727554 224.64 \r\nL 122.727554 219.594019 \r\nL 109.77591 219.594019 \r\nz\r\n\" style=\"fill:#1f77b4;\"/>\r\n   </g>\r\n   <g id=\"patch_7\">\r\n    <path clip-path=\"url(#p7ef7d1cd08)\" d=\"M 125.965465 224.64 \r\nL 138.917109 224.64 \r\nL 138.917109 200.62982 \r\nL 125.965465 200.62982 \r\nz\r\n\" style=\"fill:#1f77b4;\"/>\r\n   </g>\r\n   <g id=\"patch_8\">\r\n    <path clip-path=\"url(#p7ef7d1cd08)\" d=\"M 142.15502 224.64 \r\nL 155.106664 224.64 \r\nL 155.106664 143.787348 \r\nL 142.15502 143.787348 \r\nz\r\n\" style=\"fill:#1f77b4;\"/>\r\n   </g>\r\n   <g id=\"patch_9\">\r\n    <path clip-path=\"url(#p7ef7d1cd08)\" d=\"M 158.344575 224.64 \r\nL 171.296219 224.64 \r\nL 171.296219 56.668991 \r\nL 158.344575 56.668991 \r\nz\r\n\" style=\"fill:#1f77b4;\"/>\r\n   </g>\r\n   <g id=\"patch_10\">\r\n    <path clip-path=\"url(#p7ef7d1cd08)\" d=\"M 174.53413 224.64 \r\nL 187.485774 224.64 \r\nL 187.485774 17.554286 \r\nL 174.53413 17.554286 \r\nz\r\n\" style=\"fill:#1f77b4;\"/>\r\n   </g>\r\n   <g id=\"patch_11\">\r\n    <path clip-path=\"url(#p7ef7d1cd08)\" d=\"M 190.723685 224.64 \r\nL 203.675329 224.64 \r\nL 203.675329 105.324276 \r\nL 190.723685 105.324276 \r\nz\r\n\" style=\"fill:#1f77b4;\"/>\r\n   </g>\r\n   <g id=\"patch_12\">\r\n    <path clip-path=\"url(#p7ef7d1cd08)\" d=\"M 206.91324 224.64 \r\nL 219.864885 224.64 \r\nL 219.864885 196.03497 \r\nL 206.91324 196.03497 \r\nz\r\n\" style=\"fill:#1f77b4;\"/>\r\n   </g>\r\n   <g id=\"patch_13\">\r\n    <path clip-path=\"url(#p7ef7d1cd08)\" d=\"M 223.102796 224.64 \r\nL 236.05444 224.64 \r\nL 236.05444 208.048414 \r\nL 223.102796 208.048414 \r\nz\r\n\" style=\"fill:#1f77b4;\"/>\r\n   </g>\r\n   <g id=\"patch_14\">\r\n    <path clip-path=\"url(#p7ef7d1cd08)\" d=\"M 239.292351 224.64 \r\nL 252.243995 224.64 \r\nL 252.243995 186.277179 \r\nL 239.292351 186.277179 \r\nz\r\n\" style=\"fill:#1f77b4;\"/>\r\n   </g>\r\n   <g id=\"patch_15\">\r\n    <path clip-path=\"url(#p7ef7d1cd08)\" d=\"M 255.481906 224.64 \r\nL 268.43355 224.64 \r\nL 268.43355 170.337227 \r\nL 255.481906 170.337227 \r\nz\r\n\" style=\"fill:#1f77b4;\"/>\r\n   </g>\r\n   <g id=\"patch_16\">\r\n    <path clip-path=\"url(#p7ef7d1cd08)\" d=\"M 271.671461 224.64 \r\nL 284.623105 224.64 \r\nL 284.623105 175.800921 \r\nL 271.671461 175.800921 \r\nz\r\n\" style=\"fill:#1f77b4;\"/>\r\n   </g>\r\n   <g id=\"patch_17\">\r\n    <path clip-path=\"url(#p7ef7d1cd08)\" d=\"M 287.861016 224.64 \r\nL 300.81266 224.64 \r\nL 300.81266 200.579694 \r\nL 287.861016 200.579694 \r\nz\r\n\" style=\"fill:#1f77b4;\"/>\r\n   </g>\r\n   <g id=\"patch_18\">\r\n    <path clip-path=\"url(#p7ef7d1cd08)\" d=\"M 304.050571 224.64 \r\nL 317.002215 224.64 \r\nL 317.002215 217.455325 \r\nL 304.050571 217.455325 \r\nz\r\n\" style=\"fill:#1f77b4;\"/>\r\n   </g>\r\n   <g id=\"patch_19\">\r\n    <path clip-path=\"url(#p7ef7d1cd08)\" d=\"M 320.240126 224.64 \r\nL 333.19177 224.64 \r\nL 333.19177 223.470402 \r\nL 320.240126 223.470402 \r\nz\r\n\" style=\"fill:#1f77b4;\"/>\r\n   </g>\r\n   <g id=\"patch_20\">\r\n    <path clip-path=\"url(#p7ef7d1cd08)\" d=\"M 336.429681 224.64 \r\nL 349.381326 224.64 \r\nL 349.381326 224.422789 \r\nL 336.429681 224.422789 \r\nz\r\n\" style=\"fill:#1f77b4;\"/>\r\n   </g>\r\n   <g id=\"patch_21\">\r\n    <path clip-path=\"url(#p7ef7d1cd08)\" d=\"M 352.619237 224.64 \r\nL 365.570881 224.64 \r\nL 365.570881 224.623291 \r\nL 352.619237 224.623291 \r\nz\r\n\" style=\"fill:#1f77b4;\"/>\r\n   </g>\r\n   <g id=\"matplotlib.axis_1\">\r\n    <g id=\"xtick_1\">\r\n     <g id=\"line2d_1\">\r\n      <defs>\r\n       <path d=\"M 0 0 \r\nL 0 3.5 \r\n\" id=\"mf2d2585b54\" style=\"stroke:#000000;stroke-width:0.8;\"/>\r\n      </defs>\r\n      <g>\r\n       <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"51.493511\" xlink:href=\"#mf2d2585b54\" y=\"224.64\"/>\r\n      </g>\r\n     </g>\r\n     <g id=\"text_1\">\r\n      <!-- 0.0 -->\r\n      <defs>\r\n       <path d=\"M 56.984375 36.375 \r\nQ 56.984375 16.796875 50.859375 7.640625 \r\nQ 44.734375 -1.515625 31.84375 -1.515625 \r\nQ 18.75 -1.515625 12.71875 7.765625 \r\nQ 6.6875 17.046875 6.6875 36.28125 \r\nQ 6.6875 55.671875 12.78125 64.921875 \r\nQ 18.890625 74.171875 31.84375 74.171875 \r\nQ 44.921875 74.171875 50.953125 64.765625 \r\nQ 56.984375 55.375 56.984375 36.375 \r\nz\r\nM 44.140625 14.203125 \r\nQ 45.84375 18.171875 46.453125 23.515625 \r\nQ 47.078125 28.859375 47.078125 36.375 \r\nQ 47.078125 43.796875 46.453125 49.265625 \r\nQ 45.84375 54.734375 44.09375 58.546875 \r\nQ 42.390625 62.3125 39.421875 64.203125 \r\nQ 36.46875 66.109375 31.84375 66.109375 \r\nQ 27.25 66.109375 24.234375 64.203125 \r\nQ 21.234375 62.3125 19.484375 58.453125 \r\nQ 17.828125 54.828125 17.21875 49.015625 \r\nQ 16.609375 43.21875 16.609375 36.28125 \r\nQ 16.609375 28.65625 17.140625 23.53125 \r\nQ 17.671875 18.40625 19.4375 14.359375 \r\nQ 21.046875 10.546875 24 8.546875 \r\nQ 26.953125 6.546875 31.84375 6.546875 \r\nQ 36.421875 6.546875 39.453125 8.453125 \r\nQ 42.484375 10.359375 44.140625 14.203125 \r\nz\r\n\" id=\"Verdana-48\"/>\r\n       <path d=\"M 24.03125 0 \r\nL 12.359375 0 \r\nL 12.359375 13.921875 \r\nL 24.03125 13.921875 \r\nz\r\n\" id=\"Verdana-46\"/>\r\n      </defs>\r\n      <g transform=\"translate(43.316949 239.238437)scale(0.1 -0.1)\">\r\n       <use xlink:href=\"#Verdana-48\"/>\r\n       <use x=\"63.574219\" xlink:href=\"#Verdana-46\"/>\r\n       <use x=\"99.951172\" xlink:href=\"#Verdana-48\"/>\r\n      </g>\r\n     </g>\r\n    </g>\r\n    <g id=\"xtick_2\">\r\n     <g id=\"line2d_2\">\r\n      <g>\r\n       <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"91.967399\" xlink:href=\"#mf2d2585b54\" y=\"224.64\"/>\r\n      </g>\r\n     </g>\r\n     <g id=\"text_2\">\r\n      <!-- 2.5 -->\r\n      <defs>\r\n       <path d=\"M 57.078125 0 \r\nL 7.859375 0 \r\nL 7.859375 10.203125 \r\nQ 12.984375 14.59375 18.140625 18.984375 \r\nQ 23.296875 23.390625 27.734375 27.734375 \r\nQ 37.109375 36.8125 40.578125 42.15625 \r\nQ 44.046875 47.515625 44.046875 53.71875 \r\nQ 44.046875 59.375 40.3125 62.5625 \r\nQ 36.578125 65.765625 29.890625 65.765625 \r\nQ 25.4375 65.765625 20.265625 64.203125 \r\nQ 15.09375 62.640625 10.15625 59.421875 \r\nL 9.671875 59.421875 \r\nL 9.671875 69.671875 \r\nQ 13.140625 71.390625 18.921875 72.796875 \r\nQ 24.703125 74.21875 30.125 74.21875 \r\nQ 41.3125 74.21875 47.65625 68.8125 \r\nQ 54 63.421875 54 54.203125 \r\nQ 54 50.046875 52.953125 46.453125 \r\nQ 51.90625 42.875 49.859375 39.65625 \r\nQ 47.953125 36.625 45.390625 33.6875 \r\nQ 42.828125 30.765625 39.15625 27.203125 \r\nQ 33.9375 22.078125 28.359375 17.265625 \r\nQ 22.796875 12.453125 17.96875 8.34375 \r\nL 57.078125 8.34375 \r\nz\r\n\" id=\"Verdana-50\"/>\r\n       <path d=\"M 56.5 23.09375 \r\nQ 56.5 18.015625 54.640625 13.375 \r\nQ 52.78125 8.734375 49.5625 5.5625 \r\nQ 46.046875 2.15625 41.1875 0.3125 \r\nQ 36.328125 -1.515625 29.9375 -1.515625 \r\nQ 23.96875 -1.515625 18.453125 -0.265625 \r\nQ 12.9375 0.984375 9.125 2.734375 \r\nL 9.125 13.03125 \r\nL 9.8125 13.03125 \r\nQ 13.8125 10.5 19.1875 8.71875 \r\nQ 24.5625 6.9375 29.734375 6.9375 \r\nQ 33.203125 6.9375 36.453125 7.90625 \r\nQ 39.703125 8.890625 42.234375 11.328125 \r\nQ 44.390625 13.421875 45.484375 16.34375 \r\nQ 46.578125 19.28125 46.578125 23.140625 \r\nQ 46.578125 26.90625 45.28125 29.484375 \r\nQ 44 32.078125 41.703125 33.640625 \r\nQ 39.15625 35.5 35.515625 36.25 \r\nQ 31.890625 37.015625 27.390625 37.015625 \r\nQ 23.09375 37.015625 19.109375 36.421875 \r\nQ 15.140625 35.84375 12.25 35.25 \r\nL 12.25 72.703125 \r\nL 56 72.703125 \r\nL 56 64.15625 \r\nL 21.6875 64.15625 \r\nL 21.6875 44.828125 \r\nQ 23.78125 45.015625 25.96875 45.109375 \r\nQ 28.171875 45.21875 29.78125 45.21875 \r\nQ 35.6875 45.21875 40.125 44.21875 \r\nQ 44.578125 43.21875 48.296875 40.671875 \r\nQ 52.203125 37.984375 54.34375 33.734375 \r\nQ 56.5 29.5 56.5 23.09375 \r\nz\r\n\" id=\"Verdana-53\"/>\r\n      </defs>\r\n      <g transform=\"translate(83.790837 239.238437)scale(0.1 -0.1)\">\r\n       <use xlink:href=\"#Verdana-50\"/>\r\n       <use x=\"63.574219\" xlink:href=\"#Verdana-46\"/>\r\n       <use x=\"99.951172\" xlink:href=\"#Verdana-53\"/>\r\n      </g>\r\n     </g>\r\n    </g>\r\n    <g id=\"xtick_3\">\r\n     <g id=\"line2d_3\">\r\n      <g>\r\n       <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"132.441287\" xlink:href=\"#mf2d2585b54\" y=\"224.64\"/>\r\n      </g>\r\n     </g>\r\n     <g id=\"text_3\">\r\n      <!-- 5.0 -->\r\n      <g transform=\"translate(124.264724 239.238437)scale(0.1 -0.1)\">\r\n       <use xlink:href=\"#Verdana-53\"/>\r\n       <use x=\"63.574219\" xlink:href=\"#Verdana-46\"/>\r\n       <use x=\"99.951172\" xlink:href=\"#Verdana-48\"/>\r\n      </g>\r\n     </g>\r\n    </g>\r\n    <g id=\"xtick_4\">\r\n     <g id=\"line2d_4\">\r\n      <g>\r\n       <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"172.915175\" xlink:href=\"#mf2d2585b54\" y=\"224.64\"/>\r\n      </g>\r\n     </g>\r\n     <g id=\"text_4\">\r\n      <!-- 7.5 -->\r\n      <defs>\r\n       <path d=\"M 57.28125 61.8125 \r\nL 24.359375 0 \r\nL 13.921875 0 \r\nL 48.921875 64.15625 \r\nL 7.515625 64.15625 \r\nL 7.515625 72.703125 \r\nL 57.28125 72.703125 \r\nz\r\n\" id=\"Verdana-55\"/>\r\n      </defs>\r\n      <g transform=\"translate(164.738612 239.238437)scale(0.1 -0.1)\">\r\n       <use xlink:href=\"#Verdana-55\"/>\r\n       <use x=\"63.574219\" xlink:href=\"#Verdana-46\"/>\r\n       <use x=\"99.951172\" xlink:href=\"#Verdana-53\"/>\r\n      </g>\r\n     </g>\r\n    </g>\r\n    <g id=\"xtick_5\">\r\n     <g id=\"line2d_5\">\r\n      <g>\r\n       <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"213.389062\" xlink:href=\"#mf2d2585b54\" y=\"224.64\"/>\r\n      </g>\r\n     </g>\r\n     <g id=\"text_5\">\r\n      <!-- 10.0 -->\r\n      <defs>\r\n       <path d=\"M 52.9375 0 \r\nL 13.578125 0 \r\nL 13.578125 7.421875 \r\nL 28.71875 7.421875 \r\nL 28.71875 56.15625 \r\nL 13.578125 56.15625 \r\nL 13.578125 62.796875 \r\nQ 16.65625 62.796875 20.171875 63.296875 \r\nQ 23.6875 63.8125 25.484375 64.796875 \r\nQ 27.734375 66.015625 29.03125 67.890625 \r\nQ 30.328125 69.78125 30.515625 72.953125 \r\nL 38.09375 72.953125 \r\nL 38.09375 7.421875 \r\nL 52.9375 7.421875 \r\nz\r\n\" id=\"Verdana-49\"/>\r\n      </defs>\r\n      <g transform=\"translate(202.033594 239.238437)scale(0.1 -0.1)\">\r\n       <use xlink:href=\"#Verdana-49\"/>\r\n       <use x=\"63.574219\" xlink:href=\"#Verdana-48\"/>\r\n       <use x=\"127.148438\" xlink:href=\"#Verdana-46\"/>\r\n       <use x=\"163.525391\" xlink:href=\"#Verdana-48\"/>\r\n      </g>\r\n     </g>\r\n    </g>\r\n    <g id=\"xtick_6\">\r\n     <g id=\"line2d_6\">\r\n      <g>\r\n       <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"253.86295\" xlink:href=\"#mf2d2585b54\" y=\"224.64\"/>\r\n      </g>\r\n     </g>\r\n     <g id=\"text_6\">\r\n      <!-- 12.5 -->\r\n      <g transform=\"translate(242.507482 239.238437)scale(0.1 -0.1)\">\r\n       <use xlink:href=\"#Verdana-49\"/>\r\n       <use x=\"63.574219\" xlink:href=\"#Verdana-50\"/>\r\n       <use x=\"127.148438\" xlink:href=\"#Verdana-46\"/>\r\n       <use x=\"163.525391\" xlink:href=\"#Verdana-53\"/>\r\n      </g>\r\n     </g>\r\n    </g>\r\n    <g id=\"xtick_7\">\r\n     <g id=\"line2d_7\">\r\n      <g>\r\n       <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"294.336838\" xlink:href=\"#mf2d2585b54\" y=\"224.64\"/>\r\n      </g>\r\n     </g>\r\n     <g id=\"text_7\">\r\n      <!-- 15.0 -->\r\n      <g transform=\"translate(282.981369 239.238437)scale(0.1 -0.1)\">\r\n       <use xlink:href=\"#Verdana-49\"/>\r\n       <use x=\"63.574219\" xlink:href=\"#Verdana-53\"/>\r\n       <use x=\"127.148438\" xlink:href=\"#Verdana-46\"/>\r\n       <use x=\"163.525391\" xlink:href=\"#Verdana-48\"/>\r\n      </g>\r\n     </g>\r\n    </g>\r\n    <g id=\"xtick_8\">\r\n     <g id=\"line2d_8\">\r\n      <g>\r\n       <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"334.810726\" xlink:href=\"#mf2d2585b54\" y=\"224.64\"/>\r\n      </g>\r\n     </g>\r\n     <g id=\"text_8\">\r\n      <!-- 17.5 -->\r\n      <g transform=\"translate(323.455257 239.238437)scale(0.1 -0.1)\">\r\n       <use xlink:href=\"#Verdana-49\"/>\r\n       <use x=\"63.574219\" xlink:href=\"#Verdana-55\"/>\r\n       <use x=\"127.148438\" xlink:href=\"#Verdana-46\"/>\r\n       <use x=\"163.525391\" xlink:href=\"#Verdana-53\"/>\r\n      </g>\r\n     </g>\r\n    </g>\r\n    <g id=\"xtick_9\">\r\n     <g id=\"line2d_9\">\r\n      <g>\r\n       <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"375.284614\" xlink:href=\"#mf2d2585b54\" y=\"224.64\"/>\r\n      </g>\r\n     </g>\r\n     <g id=\"text_9\">\r\n      <!-- 20.0 -->\r\n      <g transform=\"translate(363.929145 239.238437)scale(0.1 -0.1)\">\r\n       <use xlink:href=\"#Verdana-50\"/>\r\n       <use x=\"63.574219\" xlink:href=\"#Verdana-48\"/>\r\n       <use x=\"127.148438\" xlink:href=\"#Verdana-46\"/>\r\n       <use x=\"163.525391\" xlink:href=\"#Verdana-48\"/>\r\n      </g>\r\n     </g>\r\n    </g>\r\n   </g>\r\n   <g id=\"matplotlib.axis_2\">\r\n    <g id=\"ytick_1\">\r\n     <g id=\"line2d_10\">\r\n      <defs>\r\n       <path d=\"M 0 0 \r\nL -3.5 0 \r\n\" id=\"m7fc3c7a6d6\" style=\"stroke:#000000;stroke-width:0.8;\"/>\r\n      </defs>\r\n      <g>\r\n       <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"45.989063\" xlink:href=\"#m7fc3c7a6d6\" y=\"224.64\"/>\r\n      </g>\r\n     </g>\r\n     <g id=\"text_10\">\r\n      <!-- 0 -->\r\n      <g transform=\"translate(32.63125 228.439219)scale(0.1 -0.1)\">\r\n       <use xlink:href=\"#Verdana-48\"/>\r\n      </g>\r\n     </g>\r\n    </g>\r\n    <g id=\"ytick_2\">\r\n     <g id=\"line2d_11\">\r\n      <g>\r\n       <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"45.989063\" xlink:href=\"#m7fc3c7a6d6\" y=\"191.222909\"/>\r\n      </g>\r\n     </g>\r\n     <g id=\"text_11\">\r\n      <!-- 2000 -->\r\n      <g transform=\"translate(13.557813 195.022128)scale(0.1 -0.1)\">\r\n       <use xlink:href=\"#Verdana-50\"/>\r\n       <use x=\"63.574219\" xlink:href=\"#Verdana-48\"/>\r\n       <use x=\"127.148438\" xlink:href=\"#Verdana-48\"/>\r\n       <use x=\"190.722656\" xlink:href=\"#Verdana-48\"/>\r\n      </g>\r\n     </g>\r\n    </g>\r\n    <g id=\"ytick_3\">\r\n     <g id=\"line2d_12\">\r\n      <g>\r\n       <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"45.989063\" xlink:href=\"#m7fc3c7a6d6\" y=\"157.805818\"/>\r\n      </g>\r\n     </g>\r\n     <g id=\"text_12\">\r\n      <!-- 4000 -->\r\n      <defs>\r\n       <path d=\"M 58.734375 20.453125 \r\nL 47.953125 20.453125 \r\nL 47.953125 0 \r\nL 38.578125 0 \r\nL 38.578125 20.453125 \r\nL 3.765625 20.453125 \r\nL 3.765625 31.6875 \r\nL 38.96875 72.703125 \r\nL 47.953125 72.703125 \r\nL 47.953125 28.265625 \r\nL 58.734375 28.265625 \r\nz\r\nM 38.578125 28.265625 \r\nL 38.578125 61.078125 \r\nL 10.40625 28.265625 \r\nz\r\n\" id=\"Verdana-52\"/>\r\n      </defs>\r\n      <g transform=\"translate(13.557813 161.605036)scale(0.1 -0.1)\">\r\n       <use xlink:href=\"#Verdana-52\"/>\r\n       <use x=\"63.574219\" xlink:href=\"#Verdana-48\"/>\r\n       <use x=\"127.148438\" xlink:href=\"#Verdana-48\"/>\r\n       <use x=\"190.722656\" xlink:href=\"#Verdana-48\"/>\r\n      </g>\r\n     </g>\r\n    </g>\r\n    <g id=\"ytick_4\">\r\n     <g id=\"line2d_13\">\r\n      <g>\r\n       <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"45.989063\" xlink:href=\"#m7fc3c7a6d6\" y=\"124.388726\"/>\r\n      </g>\r\n     </g>\r\n     <g id=\"text_13\">\r\n      <!-- 6000 -->\r\n      <defs>\r\n       <path d=\"M 58.15625 23.578125 \r\nQ 58.15625 12.5 50.859375 5.484375 \r\nQ 43.5625 -1.515625 32.953125 -1.515625 \r\nQ 27.59375 -1.515625 23.1875 0.140625 \r\nQ 18.796875 1.8125 15.4375 5.078125 \r\nQ 11.234375 9.125 8.953125 15.8125 \r\nQ 6.6875 22.515625 6.6875 31.9375 \r\nQ 6.6875 41.609375 8.765625 49.078125 \r\nQ 10.84375 56.546875 15.375 62.359375 \r\nQ 19.671875 67.875 26.453125 70.96875 \r\nQ 33.25 74.078125 42.28125 74.078125 \r\nQ 45.171875 74.078125 47.125 73.828125 \r\nQ 49.078125 73.578125 51.078125 72.953125 \r\nL 51.078125 63.625 \r\nL 50.59375 63.625 \r\nQ 49.21875 64.359375 46.453125 65.015625 \r\nQ 43.703125 65.671875 40.828125 65.671875 \r\nQ 30.328125 65.671875 24.078125 59.109375 \r\nQ 17.828125 52.546875 16.796875 41.359375 \r\nQ 20.90625 43.84375 24.875 45.140625 \r\nQ 28.859375 46.4375 34.078125 46.4375 \r\nQ 38.71875 46.4375 42.25 45.578125 \r\nQ 45.796875 44.734375 49.515625 42.140625 \r\nQ 53.8125 39.15625 55.984375 34.609375 \r\nQ 58.15625 30.078125 58.15625 23.578125 \r\nz\r\nM 48.25 23.1875 \r\nQ 48.25 27.734375 46.90625 30.703125 \r\nQ 45.5625 33.6875 42.484375 35.890625 \r\nQ 40.234375 37.453125 37.5 37.9375 \r\nQ 34.765625 38.421875 31.78125 38.421875 \r\nQ 27.640625 38.421875 24.078125 37.4375 \r\nQ 20.515625 36.46875 16.75 34.421875 \r\nQ 16.65625 33.34375 16.59375 32.34375 \r\nQ 16.546875 31.34375 16.546875 29.828125 \r\nQ 16.546875 22.125 18.140625 17.65625 \r\nQ 19.734375 13.1875 22.515625 10.59375 \r\nQ 24.75 8.453125 27.359375 7.453125 \r\nQ 29.984375 6.453125 33.0625 6.453125 \r\nQ 40.140625 6.453125 44.1875 10.765625 \r\nQ 48.25 15.09375 48.25 23.1875 \r\nz\r\n\" id=\"Verdana-54\"/>\r\n      </defs>\r\n      <g transform=\"translate(13.557813 128.187945)scale(0.1 -0.1)\">\r\n       <use xlink:href=\"#Verdana-54\"/>\r\n       <use x=\"63.574219\" xlink:href=\"#Verdana-48\"/>\r\n       <use x=\"127.148438\" xlink:href=\"#Verdana-48\"/>\r\n       <use x=\"190.722656\" xlink:href=\"#Verdana-48\"/>\r\n      </g>\r\n     </g>\r\n    </g>\r\n    <g id=\"ytick_5\">\r\n     <g id=\"line2d_14\">\r\n      <g>\r\n       <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"45.989063\" xlink:href=\"#m7fc3c7a6d6\" y=\"90.971635\"/>\r\n      </g>\r\n     </g>\r\n     <g id=\"text_14\">\r\n      <!-- 8000 -->\r\n      <defs>\r\n       <path d=\"M 57.625 20.265625 \r\nQ 57.625 10.84375 50.265625 4.59375 \r\nQ 42.921875 -1.65625 31.78125 -1.65625 \r\nQ 19.96875 -1.65625 12.953125 4.4375 \r\nQ 5.953125 10.546875 5.953125 20.0625 \r\nQ 5.953125 26.125 9.46875 31.03125 \r\nQ 12.984375 35.9375 19.390625 38.8125 \r\nL 19.390625 39.109375 \r\nQ 13.53125 42.234375 10.71875 45.9375 \r\nQ 7.90625 49.65625 7.90625 55.21875 \r\nQ 7.90625 63.421875 14.640625 68.890625 \r\nQ 21.390625 74.359375 31.78125 74.359375 \r\nQ 42.671875 74.359375 49.171875 69.140625 \r\nQ 55.671875 63.921875 55.671875 55.859375 \r\nQ 55.671875 50.921875 52.59375 46.15625 \r\nQ 49.515625 41.40625 43.5625 38.71875 \r\nL 43.5625 38.421875 \r\nQ 50.390625 35.5 54 31.203125 \r\nQ 57.625 26.90625 57.625 20.265625 \r\nz\r\nM 46.046875 55.765625 \r\nQ 46.046875 60.984375 42.015625 64.078125 \r\nQ 37.984375 67.1875 31.734375 67.1875 \r\nQ 25.59375 67.1875 21.65625 64.25 \r\nQ 17.71875 61.328125 17.71875 56.34375 \r\nQ 17.71875 52.828125 19.703125 50.265625 \r\nQ 21.6875 47.703125 25.6875 45.703125 \r\nQ 27.484375 44.828125 30.875 43.40625 \r\nQ 34.28125 42 37.5 41.0625 \r\nQ 42.328125 44.28125 44.1875 47.75 \r\nQ 46.046875 51.21875 46.046875 55.765625 \r\nz\r\nM 47.5625 19.34375 \r\nQ 47.5625 23.828125 45.578125 26.53125 \r\nQ 43.609375 29.25 37.84375 31.984375 \r\nQ 35.546875 33.0625 32.8125 33.984375 \r\nQ 30.078125 34.90625 25.53125 36.578125 \r\nQ 21.140625 34.1875 18.484375 30.078125 \r\nQ 15.828125 25.984375 15.828125 20.796875 \r\nQ 15.828125 14.203125 20.359375 9.90625 \r\nQ 24.90625 5.609375 31.890625 5.609375 \r\nQ 39.015625 5.609375 43.28125 9.265625 \r\nQ 47.5625 12.9375 47.5625 19.34375 \r\nz\r\n\" id=\"Verdana-56\"/>\r\n      </defs>\r\n      <g transform=\"translate(13.557813 94.770854)scale(0.1 -0.1)\">\r\n       <use xlink:href=\"#Verdana-56\"/>\r\n       <use x=\"63.574219\" xlink:href=\"#Verdana-48\"/>\r\n       <use x=\"127.148438\" xlink:href=\"#Verdana-48\"/>\r\n       <use x=\"190.722656\" xlink:href=\"#Verdana-48\"/>\r\n      </g>\r\n     </g>\r\n    </g>\r\n    <g id=\"ytick_6\">\r\n     <g id=\"line2d_15\">\r\n      <g>\r\n       <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"45.989063\" xlink:href=\"#m7fc3c7a6d6\" y=\"57.554544\"/>\r\n      </g>\r\n     </g>\r\n     <g id=\"text_15\">\r\n      <!-- 10000 -->\r\n      <g transform=\"translate(7.2 61.353763)scale(0.1 -0.1)\">\r\n       <use xlink:href=\"#Verdana-49\"/>\r\n       <use x=\"63.574219\" xlink:href=\"#Verdana-48\"/>\r\n       <use x=\"127.148438\" xlink:href=\"#Verdana-48\"/>\r\n       <use x=\"190.722656\" xlink:href=\"#Verdana-48\"/>\r\n       <use x=\"254.296875\" xlink:href=\"#Verdana-48\"/>\r\n      </g>\r\n     </g>\r\n    </g>\r\n    <g id=\"ytick_7\">\r\n     <g id=\"line2d_16\">\r\n      <g>\r\n       <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"45.989063\" xlink:href=\"#m7fc3c7a6d6\" y=\"24.137453\"/>\r\n      </g>\r\n     </g>\r\n     <g id=\"text_16\">\r\n      <!-- 12000 -->\r\n      <g transform=\"translate(7.2 27.936671)scale(0.1 -0.1)\">\r\n       <use xlink:href=\"#Verdana-49\"/>\r\n       <use x=\"63.574219\" xlink:href=\"#Verdana-50\"/>\r\n       <use x=\"127.148438\" xlink:href=\"#Verdana-48\"/>\r\n       <use x=\"190.722656\" xlink:href=\"#Verdana-48\"/>\r\n       <use x=\"254.296875\" xlink:href=\"#Verdana-48\"/>\r\n      </g>\r\n     </g>\r\n    </g>\r\n   </g>\r\n   <g id=\"patch_22\">\r\n    <path d=\"M 45.989063 224.64 \r\nL 45.989063 7.2 \r\n\" style=\"fill:none;stroke:#000000;stroke-linecap:square;stroke-linejoin:miter;stroke-width:0.8;\"/>\r\n   </g>\r\n   <g id=\"patch_23\">\r\n    <path d=\"M 380.789062 224.64 \r\nL 380.789062 7.2 \r\n\" style=\"fill:none;stroke:#000000;stroke-linecap:square;stroke-linejoin:miter;stroke-width:0.8;\"/>\r\n   </g>\r\n   <g id=\"patch_24\">\r\n    <path d=\"M 45.989063 224.64 \r\nL 380.789062 224.64 \r\n\" style=\"fill:none;stroke:#000000;stroke-linecap:square;stroke-linejoin:miter;stroke-width:0.8;\"/>\r\n   </g>\r\n   <g id=\"patch_25\">\r\n    <path d=\"M 45.989063 7.2 \r\nL 380.789062 7.2 \r\n\" style=\"fill:none;stroke:#000000;stroke-linecap:square;stroke-linejoin:miter;stroke-width:0.8;\"/>\r\n   </g>\r\n  </g>\r\n </g>\r\n <defs>\r\n  <clipPath id=\"p7ef7d1cd08\">\r\n   <rect height=\"217.44\" width=\"334.8\" x=\"45.989063\" y=\"7.2\"/>\r\n  </clipPath>\r\n </defs>\r\n</svg>\r\n",
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYkAAAD4CAYAAAAZ1BptAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+j8jraAAATaUlEQVR4nO3dfayc51nn8e8vid0XZ9cl9pAXrcChajAR2mbNoQFWeKv1JpUTsQoqIVbjAiuEu2q2lSCEhAaFuP80EKoqXsRKYbWEVaw6m7IGQaibxImXaEtrnTRssdPEjcGAUExOyUvXddsF59o/5nE7OZ3bGZ8558wc+v1Ilp+5nvue5zp3JvM7zzMvTlUhSdIw50y6AUnS9DIkJElNhoQkqcmQkCQ1GRKSpKbzJt3AQq1fv742bNgw6TYkaUV58sknv1RVvVHHr9iQ2LBhA7Ozs5NuQ5JWlCR/dTbjvdwkSWoyJCRJTYaEJKnJkJAkNRkSkqQmQ0KS1GRISJKaDAlJUpMhIUlqWrGfuJY23PbQWc85dte1S9CJ9E+XZxKSpCZDQpLUNHJIJNmU5PMDt38xyXNJnknyySS9gX23J3k2yaEkWwfqM0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jlkWSC4Efov9ZkPkK+ER3OWdX92S4XF7v2FOzhsB7gT+pqr8dsm+SawiwrqpeBqiqV+j/ljnOuKW2nTN/Buk9Sb6Y5JEkly9XUyMed+JrmOQtwI30v5C0ZdnWcN7zy5I8FldiSMAIX+Ex4pglleQNwIPA7af/o8yztao2AP8KuJhvfi/Vchjl2NOwhucCvwT8WmPIJNcQ+iE1qLVGo45bMkneD6wDfqcx5OP0n0DeBvw2cN8ytTbqcSe+hsAHgf9eVSca+5dtDYc8vyzJY3ElhsQoX+Ex8a/5SLIa+D3gk1V137AxVfW17u+TwB8C37dc/Y1w7ImvYWcb/cteR4ftnOQadl5Kcj5AkrXAi2OOWxJJfor+Gdm7q+rUsDFV9fXqLlTTv7z4tuXo7SyOO+k1/GfAzwK7WmOWaw0bzy9L8lhciSEx9Cs8kqxN8l1nGrNcDSZ5M/0nrCeq6iMD9W/02L1D4Z3d9irgx4HPLFN/Q489TWvY9XYO8MvA1K3hgMeAG7rtbQysUZKNXV9nHLfU0v/25J+jf9b1yrx93+gxyeYkb+p2vRuYXab+msedljXs3AT8j6p6zZPqcq9h6/mFpXosLuWr8Ev46v6PAYfpv8PgjvrmuwoOnGnMMvb3TuDrwDMDfz4y2CP9dyX8CfCX9L/y/DeAc5apv6HHnqY17I5/PfAH82oTW0Pgw8Dnga/S/5//39A/w3q4W6OHgd7A+AI2dNvNccvQ47Huzzcej40ef3lg3H7ge5apv+Zxp2gN3wz8NXDxkPHLvYbvZPjzy5I8Fv1aDklS00q83CRJWiaGhCSpyZCQJDUZEpKkJkNCktRkSEiSmgwJSVLT/wefugnTL/KS6AAAAABJRU5ErkJggg==\n"
     },
     "metadata": {
      "needs_background": "light"
     }
    }
   ],
   "source": [
    "plt.bar(range(1,20),len_count_list)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "#可以看见差不多15个词向量长度就可以\n",
    "\n",
    "padded_index_lines = pad_sequences(index_lines_list,padding='post',maxlen=15)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "15 [10413  5198   381   257   429    21     0     0     0     0     0     0\n     0     0     0]\n15 [   5  382 3105   33  707 1489 1490    0    0    0    0    0    0    0\n    0]\n15 [2102    4  826  102  226  107    9  322    0    0    0    0    0    0\n    0]\n15 [ 602   86 2764 3568    0    0    0    0    0    0    0    0    0    0\n    0]\n15 [  2 604 195  30  93   1  41   3  46   0   0   0   0   0   0]\n"
     ]
    }
   ],
   "source": [
    "for i in range(5):\n",
    "    print(len(padded_index_lines[i]),padded_index_lines[i])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "#创建数据集\n",
    "\n",
    "datasets = tf.data.Dataset.from_tensor_slices((padded_index_lines,labels_list))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "<TensorSliceDataset shapes: ((15,), ()), types: (tf.int32, tf.int32)>"
      ]
     },
     "metadata": {},
     "execution_count": 19
    }
   ],
   "source": [
    "datasets"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "49608"
      ]
     },
     "metadata": {},
     "execution_count": 20
    }
   ],
   "source": [
    "len(datasets)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "776"
      ]
     },
     "metadata": {},
     "execution_count": 21
    }
   ],
   "source": [
    "BATCH_SIZE = 64\n",
    "BUFFER_SIZE = len(padded_index_lines)\n",
    "datasets = datasets.shuffle(BUFFER_SIZE,reshuffle_each_iteration=False).batch(BATCH_SIZE)\n",
    "len(datasets)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "#创建模型\n",
    "model = tf.keras.Sequential()\n",
    "model.add(tf.keras.layers.Embedding(max(max_index_list)+1, 64))\n",
    "#LSTM 上的双向包装器有助于模型理解当前数据点与其之前和之后的数据点的关系\n",
    "model.add(tf.keras.layers.Bidirectional(tf.keras.layers.LSTM(64)))\n",
    "model.add(tf.keras.layers.Dense(64,activation='relu'))\n",
    "model.add(tf.keras.layers.Dense(64,activation='relu'))\n",
    "model.add(tf.keras.layers.Dense(3,activation='softmax'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "#编译模型\n",
    "model.compile(optimizer='adam',\n",
    "loss=tf.keras.losses.SparseCategoricalCrossentropy(),\n",
    "metrics=['accuracy'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "Epoch 1/5\n",
      "776/776 [==============================] - 11s 14ms/step - loss: 0.5081 - accuracy: 0.7586\n",
      "Epoch 2/5\n",
      "776/776 [==============================] - 11s 14ms/step - loss: 0.3110 - accuracy: 0.8654\n",
      "Epoch 3/5\n",
      "776/776 [==============================] - 11s 15ms/step - loss: 0.2275 - accuracy: 0.9030\n",
      "Epoch 4/5\n",
      "776/776 [==============================] - 11s 15ms/step - loss: 0.1649 - accuracy: 0.9329\n",
      "Epoch 5/5\n",
      "776/776 [==============================] - 12s 15ms/step - loss: 0.1320 - accuracy: 0.9454\n"
     ]
    },
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "<tensorflow.python.keras.callbacks.History at 0x1f218f1a550>"
      ]
     },
     "metadata": {},
     "execution_count": 24
    }
   ],
   "source": [
    "#训练模型\n",
    "model.fit(datasets,epochs=5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [],
   "source": [
    "#预测\n",
    "choose_num = 9527\n",
    "choose_line = lines_list[choose_num] \n",
    "choose_label = labels_list[choose_num]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "Through wilful negligence his force in fight!\n 0\n"
     ]
    }
   ],
   "source": [
    "print(choose_line,choose_label)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "[[78, 6091, 7419, 5, 232, 7, 69]]"
      ]
     },
     "metadata": {},
     "execution_count": 27
    }
   ],
   "source": [
    "choose_index_list = t.texts_to_sequences([choose_line])\n",
    "choose_index_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "padded_choose_index_list = pad_sequences(choose_index_list,padding='post',maxlen=15)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "choose_dataset = tf.data.Dataset.from_tensor_slices((padded_choose_index_list,[0]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "array([[  78, 6091, 7419,    5,  232,    7,   69,    0,    0,    0,    0,\n",
       "           0,    0,    0,    0]])"
      ]
     },
     "metadata": {},
     "execution_count": 29
    }
   ],
   "source": [
    "padded_choose_index_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [],
   "source": [
    "choose_tensor = tf.constant(padded_choose_index_list,dtype=tf.float32)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [],
   "source": [
    "predict = model.predict(choose_tensor)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "array([[9.9967611e-01, 3.2334196e-04, 6.0123415e-07]], dtype=float32)"
      ]
     },
     "metadata": {},
     "execution_count": 32
    }
   ],
   "source": [
    "predict"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ]
}